Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling verify! should raise a Mox.VerificationError if there are too many calls to a mock #141

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

metavida
Copy link
Contributor

@metavida metavida commented Aug 4, 2023

Similar to comments in Issue #32, there are certain cases when we want to assert that a mocked function is never called (or is not over-called) but where the expected calls happen within code that either async or has aggressive error handling. In these cases it's desirable for verify! (and verify_on_exit!) to inform the user when an expectation has been violated by receiving too many calls.

Currently this PR does not implement a solution but does contribute 4 net-new verify! unit tests that should begin passing once this behavior is implemented.

Does this seem like a reasonable request/approach?


message = ~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"
test "verifies when mocks are over-called in the process in private mode" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: The "verifies when mocks are over-called tests are the tests that are currently failing & that would be useful to me in some of the code I'm working on.

lib/mox/application.ex Outdated Show resolved Hide resolved
@metavida metavida changed the title Calling verify! should raise Mox.VerificationError if there are too many calls to a mock Calling verify! should raise a Mox.VerificationError if there are too many calls to a mock Aug 4, 2023
@josevalim
Copy link
Member

Currently this PR does not implement a solution but does contribute 4 net-new verify! unit tests that should begin passing once this behavior is implemented.

Would it be possible to add new tests instead of changing the existing suite?

@metavida metavida force-pushed the verify-too-many-calls-on-exit branch from 617a470 to f7de7fc Compare August 7, 2023 22:59
@metavida metavida force-pushed the verify-too-many-calls-on-exit branch from f7de7fc to 3121718 Compare August 7, 2023 23:03
Comment on lines +420 to +421
end)
|> Task.yield()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: Other places in this test file use a variable-based syntax instead of piping. For example: https://github.com/dashbitco/mox/blob/31217186dc7b618ea35448d2175377408a574fb3/test/mox_test.exs#L175:L181

I find this shorter, pipe-based syntax a bit nicer since it puts visual attention on the async_nolink call rather than on variable assignment, but I don't feel strongly about this choice. If you'd like me to change the syntax to match the existing code I'm happy to!

@metavida
Copy link
Contributor Author

metavida commented Aug 7, 2023

Would it be possible to add new tests instead of changing the existing suite?

Thanks for this comment! It inspired me to simplify this PR so that now it only introduces the 4 new (currently failing) tests. If you think these 4 new tests deserve to be in their own describe blocks or in their own test file just let me know!

I've separated the other, tangential improvements to verify tests into separate PR: #142

@josevalim
Copy link
Member

Perfect, Yes, this looks good to me. Looking forward to a possible solution. :)

@whatyouhide
Copy link
Collaborator

@metavida any chance you're picking this up anytime soon? Otherwise, I can give it a try.

@metavida
Copy link
Contributor Author

metavida commented Jan 21, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants